package cn.itcast.io.a.file;

import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

// File类的常用get方法演示
public class FileMethodDemo {

    public static void main(String[] args) {

        File file = new File("C:\\Users\\hz21076971\\Desktop\\myJava\\rabbitmq_info_1.txt");
        String absolutePath = file.getAbsolutePath();
        String path = file.getPath(); // 构造函数封装的是什么路径，我就拿什么路径
        String fileName = file.getName();
        long lastModified = file.lastModified();
        long fileSize = file.length();

        System.out.println("absolutePath: "+absolutePath);
        System.out.println("path: "+path);
        System.out.println("fileName: "+fileName);
        System.out.println("lastModified: "+getTime(lastModified));
        System.out.println("fileSize: "+fileSize);

        test1();
    }

    private static String getTime(long lastModified) {
        Date date = new Date(lastModified);
        DateFormat dateTimeInstance = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG);
        String formatDate = dateTimeInstance.format(date);
        //SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //String formatDate = simpleDateFormat.format(date);
        return formatDate;
    }

    private static void test1(){
        System.out.println(System.getProperty("user.dir"));
    }
}
